date

#some information about what is running:
cd /home/nucave/workdir/lattice/RENORMALIZATION/reno/NF4/Z4F/EXECUTABLES
echo "Working in: "
pwd
args=$(less args)
echo "Running:"
echo "time  ./Calc_Z4F_oneP ${args} -imom=${2} -imass=${3} -irc=${4}"


# run the program
time  ./Calc_Z4F_oneP ${args} -imom=${2} -imass=${3} -irc=${4}

echo " Program end! "

# add node when finish

log=${5}
slot=${6}
nodes=${7}
echo "adding $slot to $nodes "

cd /home/nucave/workdir/lattice/RENORMALIZATION/reno/NF4/Z4F/SCRIPTS/Calc_Z4F
pwd

echo "${slot}" >> ${nodes}

newstring="COMPLETED"
check_done=""
lockfile ${log}.lock
check_done=$(grep "In_progress" ${log} | grep ${slot})
if [[ -n ${check_done} ]]; then
      awk -v slot="$slot" -v newstring="$newstring" '{ if ($NF ~ /In_progress/ && $1 ~ slot) {sub("In_progress",newstring) ; print} else print}' ${log} >> ${log}.temp
      mv ${log}.temp ${log}
fi
rm -f ${log}.lock

lockfile ${nodes}.lock
rm -f ${nodes}.lock

date

